package com.day2.t3;

public class Main {
    public int minPathSum(int[][] grid) {
        for(int i = 0; i < grid.length; i++){
            for(int j = 0; j < grid[i].length; j++){
                int min=Integer.MAX_VALUE;
                if(i-1 >= 0){
                    min = Math.min(min, grid[i-1][j]);
                }
                if(j-1 >= 0){
                    min = Math.min(min, grid[i][j-1]);
                }
                if(min != Integer.MAX_VALUE){
                    grid[i][j] += min;
                }
            }
        }
        return grid[grid.length-1][grid[0].length-1];
    }
}
